import React from "react";
import "../css/Borard.css"
import eventEmitter from "../event";
class Borard extends React.Component{
    constructor(props){
        super(props)
        this.state={
            messages:[]
        }
    }
    render(){
        return(
            <div className="borard_container">
                { //循环
                    this.state.messages.map((element,index)=>{
                        //{}循环需要加上key值
                        return <div className="message" key={index}>
                            <h3>{element.content}</h3>
                            <h3>{element.date}</h3>
                        </div>
                    })
                }
            </div>
        );
    }

    componentDidMount(){
        eventEmitter.addListener('sendMessageTooBoard',(message)=>{
            console.log(message);
            this.state.messages.push(message);
            this.setState({
                message:this.state.messages
            })
        })
    }
}
export default Borard;